package com.juyu.miliao.api.service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import com.juyu.miliao.api.dao.mysql.GiftDao;
import com.juyu.miliao.api.service.cache.GiftCacheService;
import org.springframework.stereotype.Service;
import com.juyu.miliao.api.domain.Gift;

@Service
public class GiftService {
	@Resource
	private GiftCacheService giftCacheService;
	@Resource
	private GiftDao giftDao;

	public List<Gift> getGiftList() {
		List<Gift> giftList = giftCacheService.getGiftList();
		ArrayList<Gift> list = new ArrayList<>();
		for (Gift gift:giftList) {
			if(gift.getType()==1){
				list.add(gift);
			}
		}
		return list;
	}

	public Gift getGiftById(int id){
	 List<Gift> giftList = giftCacheService.getGiftList();
	 	Gift giftone = null;
		for (Gift gift: giftList ) {
			if(gift.getGiftId()==id){
				giftone = gift;
				break;
			}
		}
		return giftone;
	}


	public Gift getGiftByIdNoCache(int id){
		return giftDao.getGiftById(id);
	}

	public List<Gift> getGiftListByType(int type) {
		List<Gift> giftList = giftCacheService.getGiftList();
		ArrayList<Gift> list = new ArrayList<>();
		for (Gift gift:giftList) {
			if(gift.getType()==type){
				list.add(gift);
			}
		}
		return list;
	}
}
